// pages/agent/tixian.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pArr:[],
    price:'',
    limitMoney:'',
    sub:{price:''}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.load();
  },
  keyInput(s){
    console.log(s);
    let e=s.detail;
    let pArr=this.data.pArr;
    let len=pArr.length;
    if(len>=4){
      if(pArr[len-3]=="."){
        wx.util.toast('最多2位小数');
        return;
      }
    }
    if(e.value=="." && pArr.indexOf(e.value)>=0){
      return;
    }
    if(e.value=="." && pArr.length==0){
      this.setData({
        pArr:pArr.push('0')
      })
    }
    pArr.push(e.value);
    console.log(pArr);
    this.setData({
      pArr:pArr,
      'sub.price':pArr.join('')
    })
  },
  keyBack(){
    let pArr=this.data.pArr;
    pArr.splice(-1);
    this.setData({
      pArr:pArr,
      'sub.price':pArr.join('')
    })
  },
  allSet(){
    this.setData({
      pArr:this.data.price.split(''),
      'sub.price':this.data.price
    })
  },
  async load(){
    let res=await wx.util.post("agent/price");
    this.setData({
      price:res.data.money_left,
      limitMoney:res.data.min_money
    })
  },
  async done(){
    if(this.data.sub.price==""){
      wx.util.toast('请输入金额');
      return;
    }
    await wx.util.post("agent/add",this.data.sub,false);
    wx.util.toast('操作成功');
    await wx.util.sleep(500);
    wx.navigateBack();
  }
})